package cn.edu.jnu.supershopper.Game;

import android.content.Context;
import android.view.MotionEvent;

import cn.edu.jnu.supershopper.GameView;


public class Myplane extends FlyingObject{
    public int life = 3;
    public int score = 0;
    public Boolean isFire = false;
    public Boolean isDied = false;

    public Myplane(Context context, int resourceId) {
        super(context, resourceId);
        speed = 5;
    }

    //移动飞机
    public void touchEvent(MotionEvent event){
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            float ex = event.getX();
            float ey = event.getY();
            if(ex>posX && ex< posX+width &&ey>posY&&ey<posY+height){
                posX = (int)ex - width/2;
                posY = (int)ey - height/2;
                if(posY<0) posY=0;
                if(posY > GameView.mScreenWidth - height)
                    posY = GameView.mScreenHeight-height;
                if(posX<0) posX=0;
                if(posX>GameView.mScreenWidth-width)
                    posX = GameView.mScreenWidth - width;
            }
        }
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            float ex = event.getX();
            if(ex>(float) GameView.mScreenWidth/2) posX+=20;
            else posX-=20;
        }
    }
}

